package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllSites", query = "select mySite from Site mySite"),
		@NamedQuery(name = "findSiteByDefaultLanguage", query = "select mySite from Site mySite where mySite.defaultLanguage = ?1"),
		@NamedQuery(name = "findSiteByDefaultLanguageContaining", query = "select mySite from Site mySite where mySite.defaultLanguage like ?1"),
		@NamedQuery(name = "findSiteById", query = "select mySite from Site mySite where mySite.id = ?1"),
		@NamedQuery(name = "findSiteByLdapPassword", query = "select mySite from Site mySite where mySite.ldapPassword = ?1"),
		@NamedQuery(name = "findSiteByLdapPasswordContaining", query = "select mySite from Site mySite where mySite.ldapPassword like ?1"),
		@NamedQuery(name = "findSiteByLdapRootdn", query = "select mySite from Site mySite where mySite.ldapRootdn = ?1"),
		@NamedQuery(name = "findSiteByLdapRootdnContaining", query = "select mySite from Site mySite where mySite.ldapRootdn like ?1"),
		@NamedQuery(name = "findSiteByLdapUrl", query = "select mySite from Site mySite where mySite.ldapUrl = ?1"),
		@NamedQuery(name = "findSiteByLdapUrlContaining", query = "select mySite from Site mySite where mySite.ldapUrl like ?1"),
		@NamedQuery(name = "findSiteByLdapUser", query = "select mySite from Site mySite where mySite.ldapUser = ?1"),
		@NamedQuery(name = "findSiteByLdapUserContaining", query = "select mySite from Site mySite where mySite.ldapUser like ?1"),
		@NamedQuery(name = "findSiteByLogo", query = "select mySite from Site mySite where mySite.logo = ?1"),
		@NamedQuery(name = "findSiteByLongDateFormat", query = "select mySite from Site mySite where mySite.longDateFormat = ?1"),
		@NamedQuery(name = "findSiteByLongDateFormatContaining", query = "select mySite from Site mySite where mySite.longDateFormat like ?1"),
		@NamedQuery(name = "findSiteByNumberOfUsers", query = "select mySite from Site mySite where mySite.numberOfUsers = ?1"),
		@NamedQuery(name = "findSiteByPrimaryKey", query = "select mySite from Site mySite where mySite.id = ?1"),
		@NamedQuery(name = "findSiteByRenewDate", query = "select mySite from Site mySite where mySite.renewDate = ?1"),
		@NamedQuery(name = "findSiteByShortDateFormat", query = "select mySite from Site mySite where mySite.shortDateFormat = ?1"),
		@NamedQuery(name = "findSiteByShortDateFormatContaining", query = "select mySite from Site mySite where mySite.shortDateFormat like ?1"),
		@NamedQuery(name = "findSiteByStorageLimit", query = "select mySite from Site mySite where mySite.storageLimit = ?1"),
		@NamedQuery(name = "findSiteBySubDomain", query = "select mySite from Site mySite where mySite.subDomain = ?1"),
		@NamedQuery(name = "findSiteBySubDomainContaining", query = "select mySite from Site mySite where mySite.subDomain like ?1"),
		@NamedQuery(name = "findSiteBySyncInd", query = "select mySite from Site mySite where mySite.syncInd = ?1"),
		@NamedQuery(name = "findSiteBySyncIndContaining", query = "select mySite from Site mySite where mySite.syncInd like ?1"),
		@NamedQuery(name = "findSiteBySyncInterval", query = "select mySite from Site mySite where mySite.syncInterval = ?1") })
@Table(catalog = "sow", name = "site")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "Site")
public class Site implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "LOGO")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer logo;
	/**
	 */

	@Column(name = "SUB_DOMAIN", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String subDomain;
	/**
	 */

	@Column(name = "DEFAULT_LANGUAGE", length = 5)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String defaultLanguage;
	/**
	 */

	@Column(name = "NUMBER_OF_USERS")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer numberOfUsers;
	/**
	 */

	@Column(name = "STORAGE_LIMIT")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer storageLimit;
	/**
	 */

	@Column(name = "SHORT_DATE_FORMAT", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String shortDateFormat;
	/**
	 */

	@Column(name = "LONG_DATE_FORMAT", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String longDateFormat;
	/**
	 */

	@Column(name = "SYNC_IND", length = 1)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String syncInd;
	/**
	 */

	@Column(name = "SYNC_INTERVAL")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer syncInterval;
	/**
	 */

	@Column(name = "LDAP_URL", length = 100)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String ldapUrl;
	/**
	 */

	@Column(name = "LDAP_ROOTDN", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String ldapRootdn;
	/**
	 */

	@Column(name = "LDAP_USER", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String ldapUser;
	/**
	 */

	@Column(name = "LDAP_PASSWORD", length = 100)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String ldapPassword;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "RENEW_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar renewDate;

	/**
	 */
	@OneToOne(fetch = FetchType.EAGER)
	@JoinColumns({ @JoinColumn(name = "CLIENT_ID", referencedColumnName = "ID", unique = true, nullable = false) })
	@XmlTransient
	Client client;
	/**
	 */
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumns({ @JoinColumn(name = "ADMIN_ID", referencedColumnName = "ID") })
	@XmlTransient
	User user;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setLogo(Integer logo) {
		this.logo = logo;
	}

	/**
	 */
	public Integer getLogo() {
		return this.logo;
	}

	/**
	 */
	public void setSubDomain(String subDomain) {
		this.subDomain = subDomain;
	}

	/**
	 */
	public String getSubDomain() {
		return this.subDomain;
	}

	/**
	 */
	public void setDefaultLanguage(String defaultLanguage) {
		this.defaultLanguage = defaultLanguage;
	}

	/**
	 */
	public String getDefaultLanguage() {
		return this.defaultLanguage;
	}

	/**
	 */
	public void setNumberOfUsers(Integer numberOfUsers) {
		this.numberOfUsers = numberOfUsers;
	}

	/**
	 */
	public Integer getNumberOfUsers() {
		return this.numberOfUsers;
	}

	/**
	 */
	public void setStorageLimit(Integer storageLimit) {
		this.storageLimit = storageLimit;
	}

	/**
	 */
	public Integer getStorageLimit() {
		return this.storageLimit;
	}

	/**
	 */
	public void setShortDateFormat(String shortDateFormat) {
		this.shortDateFormat = shortDateFormat;
	}

	/**
	 */
	public String getShortDateFormat() {
		return this.shortDateFormat;
	}

	/**
	 */
	public void setLongDateFormat(String longDateFormat) {
		this.longDateFormat = longDateFormat;
	}

	/**
	 */
	public String getLongDateFormat() {
		return this.longDateFormat;
	}

	/**
	 */
	public void setSyncInd(String syncInd) {
		this.syncInd = syncInd;
	}

	/**
	 */
	public String getSyncInd() {
		return this.syncInd;
	}

	/**
	 */
	public void setSyncInterval(Integer syncInterval) {
		this.syncInterval = syncInterval;
	}

	/**
	 */
	public Integer getSyncInterval() {
		return this.syncInterval;
	}

	/**
	 */
	public void setLdapUrl(String ldapUrl) {
		this.ldapUrl = ldapUrl;
	}

	/**
	 */
	public String getLdapUrl() {
		return this.ldapUrl;
	}

	/**
	 */
	public void setLdapRootdn(String ldapRootdn) {
		this.ldapRootdn = ldapRootdn;
	}

	/**
	 */
	public String getLdapRootdn() {
		return this.ldapRootdn;
	}

	/**
	 */
	public void setLdapUser(String ldapUser) {
		this.ldapUser = ldapUser;
	}

	/**
	 */
	public String getLdapUser() {
		return this.ldapUser;
	}

	/**
	 */
	public void setLdapPassword(String ldapPassword) {
		this.ldapPassword = ldapPassword;
	}

	/**
	 */
	public String getLdapPassword() {
		return this.ldapPassword;
	}

	/**
	 */
	public void setRenewDate(Calendar renewDate) {
		this.renewDate = renewDate;
	}

	/**
	 */
	public Calendar getRenewDate() {
		return this.renewDate;
	}

	/**
	 */
	public void setClient(Client client) {
		this.client = client;
	}

	/**
	 */
	@JsonIgnore
	public Client getClient() {
		return client;
	}

	/**
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 */
	@JsonIgnore
	public User getUser() {
		return user;
	}

	/**
	 */
	public Site() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Site that) {
		setId(that.getId());
		setLogo(that.getLogo());
		setSubDomain(that.getSubDomain());
		setDefaultLanguage(that.getDefaultLanguage());
		setNumberOfUsers(that.getNumberOfUsers());
		setStorageLimit(that.getStorageLimit());
		setShortDateFormat(that.getShortDateFormat());
		setLongDateFormat(that.getLongDateFormat());
		setSyncInd(that.getSyncInd());
		setSyncInterval(that.getSyncInterval());
		setLdapUrl(that.getLdapUrl());
		setLdapRootdn(that.getLdapRootdn());
		setLdapUser(that.getLdapUser());
		setLdapPassword(that.getLdapPassword());
		setRenewDate(that.getRenewDate());
		setClient(that.getClient());
		setUser(that.getUser());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("logo=[").append(logo).append("] ");
		buffer.append("subDomain=[").append(subDomain).append("] ");
		buffer.append("defaultLanguage=[").append(defaultLanguage).append("] ");
		buffer.append("numberOfUsers=[").append(numberOfUsers).append("] ");
		buffer.append("storageLimit=[").append(storageLimit).append("] ");
		buffer.append("shortDateFormat=[").append(shortDateFormat).append("] ");
		buffer.append("longDateFormat=[").append(longDateFormat).append("] ");
		buffer.append("syncInd=[").append(syncInd).append("] ");
		buffer.append("syncInterval=[").append(syncInterval).append("] ");
		buffer.append("ldapUrl=[").append(ldapUrl).append("] ");
		buffer.append("ldapRootdn=[").append(ldapRootdn).append("] ");
		buffer.append("ldapUser=[").append(ldapUser).append("] ");
		buffer.append("ldapPassword=[").append(ldapPassword).append("] ");
		buffer.append("renewDate=[").append(renewDate).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Site))
			return false;
		Site equalCheck = (Site) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
